/*
 * Created by SharpDevelop.
 * User: Slon
 * Date: 03.02.2009
 * Time: 9:16
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System.IO;
using System.Xml;

namespace IMSAT.OFTD.DOM
{
    /// <summary>
    /// Description of SvgNode.
    /// </summary>
    public class SvgNode : Node
    {
        private readonly MemoryStream _data = new MemoryStream();

        public MemoryStream Data
        {
            get { return _data; }
        }

        #region Nested type: Reader

        public class Reader : NodeXmlReader
        {
            protected override bool CheckReader(XmlReader rd, bool _prevRes, Node parentNode)
            {
                if (_prevRes)
                {
                    var nspm = new OFTDCommonNamespaceManager();
                    string ns = rd.NamespaceURI;
                    if (ns == nspm.SVGNamespace.Namespace && rd.LocalName == "svg")
                        return true;
                    return false;
                }
                return base.CheckReader(rd, _prevRes, parentNode);
            }

            protected override Node InitNode(XmlReader reader, Node initedNode)
            {
                if (initedNode == null)
                    initedNode = new SvgNode();
                var n = (SvgNode) initedNode;
                XmlWriter wr = XmlWriter.Create(n.Data);
                wr.WriteNode(reader, false);
                wr.Flush();
                return base.InitNode(reader, initedNode);
            }
        }

        #endregion
    }
}